package first.group.ssh.channel.session;

import first.group.ssh.channel.ChannelRequest;
import first.group.ssh.packet.writer.StringWriter;
import java.nio.ByteBuffer;

public class PtyRequest extends ChannelRequest {
    
    public final String termType;
    public final int widthChar, heightChar;
    public final int widthPixels, heightPixels;
    public final byte[] termMode;

    public PtyRequest(int widthChar, int heightChar) {
        this(false, widthChar, heightChar);
    }

    public PtyRequest(boolean wantReply, int widthChar, int heightChar) {
        this(wantReply, "dumb", widthChar, heightChar);
    }

    public PtyRequest(boolean wantReply, String termType, int widthChar, int heightChar) {
        this(wantReply, "dumb", widthChar, heightChar, 0, 0, new byte[1]);
    }
    
    public PtyRequest(boolean wantReply, String termType, int widthChar, int heightChar, int widthPixels, int heightPixels, byte[] termMode) {
        super(wantReply);
        this.termType = termType;
        this.widthChar = widthChar;
        this.heightChar = heightChar;
        this.widthPixels = widthPixels;
        this.heightPixels = heightPixels;
        this.termMode = termMode;
    }

    @Override
    public String getName() {
        return "pty-req";
    }

    @Override
    public void write(ByteBuffer buffer) {
        StringWriter.writeString(buffer, termType);
        buffer.putInt(widthChar);
        buffer.putInt(widthPixels);
        buffer.putInt(heightChar);
        buffer.putInt(widthPixels);
        StringWriter.writeByteArray(buffer, termMode);
    }
}
